<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{:session('cp.cpsysname')}--系统管理平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="{:config('webconfig.description');}">
    <meta name="keywords" content="{:config('webconfig.keywords');}">
    <meta name="author" content="runoob">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/bootstrapSwitch.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/index.css"/>
    <script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
    <script src="__STATIC_URL__/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="__STATIC_URL__/static/js/commen.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC_URL__/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <style>
        tbody td {
            text-align: center;
            vertical-align: middle !important;
        }
    </style>
</head>
<body>
{include file='public/header'/}
<section>
    <!------------------导航-------------------------->
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading mgr15 mgl15">
            <ul class="breadcrumb">
                <li>当前位置是&nbsp;:</li>
                <li>
                    <a href="javascript:;">员工管理</a>
                </li>
                <li class="active" style="color: #02b87f;"> 用户列表</li>
            </ul>
        </div>
        <div class="panel panel-default panel-search mgr15 mgl15">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <span class="glyphicon glyphicon-search pull-left" style="margin-right: 10px;"></span>人员查找
                </h3>
            </div>
            <div class="panel-body">
                <form action="" method="get" class="form-horizontal table-search form-search" role="form" id="machform">
                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4 ">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">姓名：</label>
                            <div class="col-sm-9">
                                <input type="text" autocomplete="off" disableautocomplete class="form-control"
                                       placeholder="请输入用户姓名" value="{$p_data['xingming']}" name="xingming">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4 ">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">门店：</label>
                            <div class="col-sm-9">
                                <select name="mid" class="form-control">
                                    <option value="">所有门店</option>
                                    {volist name="mach" id="search"}
                                    <option value="{$search.id}" {if condition="$p_data['mid'] eq $search.id" }selected{/if}>{$search.merchant}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="panel-footer">
                <a href="javascript:;" class="btn btn-primary" onclick="searchform()">查找</a>
                <a href="javascript:;" class="btn btn-default" onclick="clearform()">清空</a>
            </div>
        </div>
        <div class="panel mgl15 mgr15">
            <div class="panel-heading addCharts" style="background:#ededed;">用户列表
                {if condition="checkPath('personnel/cashieradd')"}
                <a class="btn btn-info pull-right" href="{:url('Personnel/cashieradd')}"style="margin-top: -7px;">添加新员工</a>
                {/if}
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th class="text-center">姓名</th>
                        <th class="text-center">帐号</th>
                        <th class="text-center">工号</th>
                        <th class="text-center">手机号</th>

                        <th class="text-center">角色</th>
                        <th class="text-center">所属门店</th>
                        <th class="hidden-phone text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="vo"}
                    <tr>
                        <td>{$vo.xingming}</td>
                        <td>{$vo.username}</td>
                        <td>{$vo.gonghao}</td>
                        <td>{$vo.tel}</td>
                        <td>{:getuserlevel($vo.level)}</td>
                        <td>{:getmachname($vo.mid)}</td>
                        <td>
                            {if condition="checkPath('personnel/cashieredit')"}
                            <a style="display: inline-block;" class=" btn-link" href="{:url('Personnel/cashieredit',['id'=>$vo['id']])}">详情</a>
                            {/if}
                            {if condition="checkPath('personnel/cashierdel')"}
                            <a style="display: inline-block;" href="javascript:;" class=" btn-link del" data-id="{$vo.id}" >删除</a>
                            {/if}
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
            <!--分页-->
        </div>
        {include file='public/footer'/}
    </div>
</section>
<script src="__STATIC_URL__/static/js/template.js"></script>
<script id="modallist" type="text/html">
    {{each list value i}}
    <li class="list-group-item">
        <form action="" >
            <div class="pull-right">
                <input type="hidden" name="is_tz" value="{{list[i].is_tz.is_tz}}">
                <input type="hidden" name="openid" value="{{openid}}">
                <input type="hidden" name="mid" value="{{list[i].id}}">
                <input type="checkbox" class="create-switch" {{ if (list[i].is_tz.is_tz=="1" )}} checked {{/if}}/>
            </div>
        </form>
        <span>{{list[i].merchant}}</span>
    </li>
    {{/each}}
</script>
</body>
<script src="__STATIC_URL__/static/js/qrcode/qrcode.js"></script>
<script src="__STATIC_URL__/static/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
//        获取微信通知列表
        $('#wechat').on('show.bs.modal', function () {
            var openid = $(event.target).data("openid");
            var datas = {};
            $.ajax({
                url: "{:url('personnel/per_machlist')}",
                type: "post",
                data: {
                    openid: openid
                },
                success: function (data) {
//                   定义返回的数据为一个json
                    datas.list = data;
                    datas.openid = openid;
                    var html = template('modallist', datas);
                    $("#list-group").html(html);
//                    初始化开关按钮
                    $('.create-switch').wrap('<div class="switch switch-small" data-on-label="开" data-off-label="关"/>').parent().bootstrapSwitch();
//                    判断是否有权限设置通知状态
                    var qx = "{:checkPath('personnel/add_cashier')}";
                    if(qx==0){
                        $('.switch').bootstrapSwitch('setActive', false);
                        return false;
                    }
//                    通知按钮开关切换
                    $('.switch').on('switch-change', function (e, data) {
                        var $el = $(data.el), value = data.value;
                        var elm = $el.parentsUntil("form").find("input[name='is_tz']");
                        if (value == true) {
                            elm.val("1");
                        } else if (value == false) {
                            elm.val("0");
                        }
                        var datas = $el.parent().parent().parent().parent().serialize();
                        $.ajax({
                            url: "{:url('personnel/add_cashier')}",
                            type: "post",
                            data: datas,
                            success: function (data) {
                                if (data.code == 0) {
                                    layer.msg("设置成功", {icon: 1, time: 1000});
                                    return false;
                                } else {
                                    layer.alert(data.message, {icon: 7});
                                    return false;
                                }
                            }
                        })
                    });
                }
            })
        });
//        删除员工方法
        $(".del").click(function () {
            var id = $(this).attr("data-id");
            //询问框
            layer.confirm('确认删除该员工吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('personnel/cashierdel')}",
                    type: "post",
                    async: true,
                    data: {
                        id: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg("删除成功", {time: 500, icon: 1});
                            setTimeout("window.location.reload()", 500);
                            return false;
                        } else {
                            layer.alert(data.message, {icon: 7});
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        //        员工解绑操作方法
        $(".delbang").click(function () {
            var id = $(this).attr("data-id");
            //询问框
            layer.confirm('确认对该员工进行解绑操作吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('personnel/cashierunbin')}",
                    type: "post",
                    async: true,
                    data: {
                        id: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.message, {time: 500, icon: 1});
                            setTimeout("window.location.reload()", 500);
                            return false;
                        } else {
                            layer.alert(data.message, {icon: 7});
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
//        监听模态框关闭 清空扫描二维码
        $("#myModal").on('hide.bs.modal', function () {
            $("#saomiao").html('');
        });
        $("#binduser").click(function () {
            $.ajax({
                url: "{:url('personnel/cashierbinding')}",
                type: "post",
                async: "true",
                data: $("#bangding_frm").serialize(),
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.message);
                        $("#myModal").modal("hide");
                        setTimeout("window.location.reload()", 500)
                        return false;
                    } else {
                        layer.alert(data.message);
                    }
                }
            })
        });
        $('.bangding').click(function () {
            var cashier = $(this).attr('data-id');
            var uid = $(this).attr("data-uid");
            $.ajax({
                type: 'post',
                url: "{:url('Personnel/getcashier_info')}",
                data: {
                    id: cashier,
                },
                success: function (data) {
                    new QRCode($(".ng-isolate-scope")[0], {
                        text: data.login_url,
                        width: 100,
                        height: 100,
                        colorDark: '#000000',
                        colorLight: '#ffffff',
                        correctLevel: QRCode.CorrectLevel.L
                    });
                    $('#cashier_id').val(cashier);
                    $("#bind-uid").val(uid);
                    $('.xingming').text(data.xingming);
                    $('.gonghao').text(data.gonghao);
                    $('#myModal').modal('show');
                    connectT(data.shuju);
                }
            })
        });
    });
</script>
<script type="text/javascript">
    var c = "MozWebSocket" in window ? 'MozWebSocket' : ("WebSocket" in window ? 'WebSocket' : null);

    function connectT(code) {
        wss = new WebSocket("wss://paydemo.weilinzhou.com:10223");
        wss.onopen = function () {
            wss.send(code);
        };
        wss.onmessage = function (e) {
            var data = eval('(' + e.data + ')');
            if (data.code == 0) {
                $('#openid').val(data.openid);
                $('#headimg').attr('src', data.headimg);
                $("#headimgs").val(data.headimg);
                $('#nickname').val(data.nickname);

            }


        };
    }

</script>

</body>
</html>